import { request } from '@/app/http'
import { toPageParam, toPageResult, toRangeParam } from 'app/converter'

const PATH = '/school/cooperations'

export async function searchCooperation(params, pageData) {
  const { data } = await request({
    url: PATH,
    method: 'get',
    params: { ...toRangeParam(params), ...toPageParam(pageData) }
  })
  return toPageResult(data)
}

export function addCooperation(data) {
  return request({
    url: PATH,
    method: 'post',
    data: {
      ...toRangeParam(
        data,
        'projectCycle',
        'projectCycleStart',
        'projectCycleEnd'
      )
    }
  })
}

export function updateCooperation(data) {
  return request({
    url: PATH,
    method: 'put',
    data: {
      ...toRangeParam(
        data,
        'projectCycle',
        'projectCycleStart',
        'projectCycleEnd'
      )
    }
  })
}

export function removeCooperation(data) {
  return request({
    url: PATH,
    method: 'delete',
    data,
    showLoading: true,
    showMsg: true
  })
}

export function downloadCooperation(params) {
  return request({
    url: PATH + '/download',
    method: 'get',
    params,
    responseType: 'blob',
    showLoading: true,
    showMsg: true
  })
}

export function getCooperationDetail(params) {
  return request({
    url: PATH + '/getDetailById',
    method: 'get',
    params
  })
}
